﻿#include "UIPlayControl.h"
#include "PlayConfig.h"
#include "QtPotPlayer.h"
#include "UIModel/UIPlayModel.h"
#include "UIView/UIPlayView.h"
#include "Utils/QPTypes.h"
#include "Utils/GloabTool/FuncTools.h"

UIPlayControl::UIPlayControl(QWidget *parent)
    :QObject(parent)
{
    MainUI = static_cast<QtPotPlayer*>(parent);
    playModel = new UIPlayModel(this);
    playModel->setEngine(QP::QTMEDIA);
    playModel->setVideoWidget(MainUI->CurrentWidget(0));
    
    this->PlayView  = new UIPlayView();
    
    connect(MainUI,&QtPotPlayer::SigBtnPlayCtrlObj,this,&UIPlayControl::Play);
    connect(MainUI,&QtPotPlayer::SigBtnStopObj,this,&UIPlayControl::Stop);
    connect(MainUI,&QtPotPlayer::SigBtnPreviousObj,this,&UIPlayControl::Previous);
    connect(MainUI,&QtPotPlayer::SigBtnNextObj,this,&UIPlayControl::Next);
    connect(MainUI,&QtPotPlayer::SigBtnOpenObj,this,&UIPlayControl::OpenFileDialog);
    connect(MainUI,&QtPotPlayer::SigBtnPlayConfigObj,this,&UIPlayControl::PlayConfig);
    isPlaying = false;
    playModel->setMedia(QUrl("/home/chenx/Videos/dde-introduction.mp4"));
}

void UIPlayControl::Play(QPushButton *obj)
{    
    if(!isPlaying)
    {
        PlayView->SetPlayCtrlIco(obj,true);
        isPlaying = true;
        playModel->Play();
        MainUI->setCurrentIndex(0);
        qout << "UI发命令，播放音乐";
        return;
    }
    if(isPlaying)
    {
        PlayView->SetPlayCtrlIco(obj,false);
        playModel->Pause();
        isPlaying = false;
        qout << "UI发命令，暂停音乐";
        return;
    }
}

void UIPlayControl::Stop(QPushButton *obj)
{
    MainUI->setCurrentIndex(1);
    playModel->Stop();
    PlayView->SetPlayCtrlIco(obj,false);
    isPlaying = false;
    qout << "UI发命令，停止音乐";
}

void UIPlayControl::Previous()
{
    qout << "UI发命令，上一曲";
}

void UIPlayControl::Next()
{
    qout << "UI发命令，下一曲";
    
}

void UIPlayControl::OpenFileDialog()
{
    qout << "UI发命令，打开文件对话框";
}

void UIPlayControl::PlayConfig()
{
    qout << "UI发命令，打开配置对话框";
}
